03. Video + Quiz: Write Your First Subquery

Your First Subquery

Your First Subquery

The first time you write a subquery it might seem really complex. Let's try breaking it down into its different parts.

If you get stuck look again at the video above. We want to find the average number of events for each day for each channel. The first table will provide us the number of events for each day and channel, and then we will need to average these values together using a second query.

You try solving this yourself.

Task Description:

Tasks to complete.

Task List:

Task Feedback:

Nice job! Understanding how to nest one query within another query is key to answering many questions that pertain to any company storing data in a relational database.

Code

If you need a code on the https://github.com/udacity.

Quiz 1

On which day-channel pair did the most events occur. (Mark all that are true)

SOLUTION:
  • January 1, 2017; direct
  • December 21, 2016; direct

Quiz 2

Mark all of the below that are true regarding writing your subquery.

SOLUTION:
  • The original query goes in the **FROM** statement.
  • An `*` is used in the **SELECT** statement to pull all of the data from the original query.
  • You **MUST** use an alias for the table you nest within the outer query.

QUIZ QUESTION::

Match each channel to its corresponding average number of events per day.

ANSWER CHOICES:



Channel

Average Number of Events/Day

direct

facebook

organic

twitter

SOLUTION:

Channel

Average Number of Events/Day

organic

facebook

twitter

direct